﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using JSC.Portal.Entities;
using JSC.Portal.Module;
using JSC.Portal.Web.App.Modules.ContactUs.Services;
using System.Web.UI.WebControls;
using JSC.Portal.Web.App.Modules.ContactUs.Entities;
using System.Net.Mail;
using System.Configuration;

namespace JSC.Portal.Web.App.Modules.ContactUs
{
    public class ContactUsModule: ServicedModule<IContactUsService>
    {
        public ContactUsModule(Section section) : base(section) { }

        public void SendMail(Contact contact)
        {
            using (MailMessage message = new MailMessage(contact.EMail, Section.Page.PortalSite.WebmasterMail))
            {
                message.Subject = contact.Subject;
                message.IsBodyHtml = false;
                message.Body = string.Format("{0}\r\n\r\n{1}\r\n\r\n{2} {3}\r\n{4}\r\n{5}", contact.Subject,
                    contact.Message, contact.Title, contact.Name, contact.EMail, contact.PhoneNumber);
                try
                {
                    SmtpClient client = new SmtpClient(ConfigurationManager.AppSettings["SMTPServer"]);
                    client.Send(message);
                }
                catch(Exception ex)
                {
                    throw new Exception(Resources.Msg.EMailFault, ex);
                }
            }
        }
    }
}
